﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace GodofTroll
{
    class Introducao: Game1
    {
        private Game1 game1;
        private Viewport viewport;
        private Controles controles;
        private int kbDelay = 0;

        private Texture2D aberturaTextura;
        private Vector2 aberturaPosicao;
        private Vector2 aberturaOrigin;
        private float aberturaScale = 1f;
        private float aberturaTempo;
        private Texture2D introOlimpo;
        private Texture2D introBanheira;
        private Texture2D introZeus;
        private Texture2D introMojo;
        private Texture2D introFuga;
        private Texture2D introMenu;

        //public List<Botoes> listaBotoes = new List<Botoes>();
        //private Botoes botaoJogo, botaoCreditos, botaoSair;
        //public int botaoSelecionado = 0;
        
        private SpriteFont textoFonte;
        private Vector2 textoPosicao;
        private float textoScale;
        private Vector2 textoOrigin;
        private string textoTexto;

        private TimeSpan tempo3s = new TimeSpan(0, 0, 3);
        private Color cor = Color.White;
        private float alphaOut = 0.0f;
        private float alphaIn = 2.0f;
        private Texture2D fadeTextura;
       
        public Introducao(Game1 game1)
        {
            this.game1 = game1;
            controles = new Controles();
            CarregaContent();
        }

        public virtual void CarregaContent()
        {
            #region - Imagens da Introducao
            aberturaTextura = game1.Content.Load<Texture2D>("Telas\\fundopreto");
            introOlimpo= game1.Content.Load<Texture2D>("Telas\\ceudegrademontanhacomolimpo");
            introBanheira = game1.Content.Load<Texture2D>("Telas\\olimpodentrocomaguaeceu");
            introZeus = game1.Content.Load<Texture2D>("Telas\\zeusBebendo");
            fadeTextura = game1.Content.Load<Texture2D>("Telas\\fade");
            introMojo = game1.Content.Load<Texture2D>("Telas\\mojoRoubado");
            introFuga = game1.Content.Load<Texture2D>("Telas\\manFugindo");
            introMenu = game1.Content.Load<Texture2D>("Telas\\menuFrascoLT");
            #endregion

            //#region - Carregamento dos botoes
            //switch (game1.telas)
            //{
            //    case GameState.Menu:
            //        botaoJogo = new Botoes(game1);
            //        botaoJogo.botaoTexture = game1.Content.Load<Texture2D>("Botoes\\botaoJogo");
            //        botaoJogo.botaoPosition = new Vector2(game1.graphics.PreferredBackBufferWidth / 2, game1.graphics.PreferredBackBufferHeight / 2 + 75);
            //        botaoJogo.botaoRectangle = new Rectangle(0, 0, 160, botaoJogo.botaoTexture.Height);
            //        botaoJogo.botaoOrigin = new Vector2(botaoJogo.botaoTexture.Width / 4, botaoJogo.botaoTexture.Height / 2);


            //        botaoCreditos = new Botoes(game1);
            //        botaoCreditos.botaoTexture = game1.Content.Load<Texture2D>("Botoes\\botaoCreditos");
            //        botaoCreditos.botaoPosition = new Vector2(game1.graphics.PreferredBackBufferWidth / 2, game1.graphics.PreferredBackBufferHeight / 2 + 80 + botaoCreditos.botaoTexture.Height);
            //        botaoCreditos.botaoRectangle = new Rectangle(0, 0, 160, botaoCreditos.botaoTexture.Height);
            //        botaoCreditos.botaoOrigin = new Vector2(botaoCreditos.botaoTexture.Width / 4, botaoCreditos.botaoTexture.Height / 2);

            //        botaoSair = new Botoes(game1);
            //        botaoSair.botaoTexture = game1.Content.Load<Texture2D>("Botoes\\botaoSair");
            //        botaoSair.botaoPosition = new Vector2(game1.graphics.PreferredBackBufferWidth / 2, game1.graphics.PreferredBackBufferHeight / 2 + 85 + botaoJogo.botaoTexture.Height + botaoCreditos.botaoTexture.Height);
            //        botaoSair.botaoRectangle = new Rectangle(0, 0, 160, botaoSair.botaoTexture.Height);
            //        botaoSair.botaoOrigin = new Vector2(botaoSair.botaoTexture.Width / 4, botaoSair.botaoTexture.Height / 2);

            //        listaBotoes.Add(botaoJogo);
            //        listaBotoes.Add(botaoCreditos);
            //        listaBotoes.Add(botaoSair);

            //        game1.Components.Add(botaoJogo);
            //        game1.Components.Add(botaoCreditos);
            //        game1.Components.Add(botaoSair);
            //        break;
            //}
            //#endregion
        
        }

        public virtual void UnLoadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
        }

        public virtual void aberturaDraw(GameTime gameTime, SpriteBatch spriteBatch)
        {
             switch (game1.telas)
            {
                #region Abertura
                case GameState.Abertura:
                    viewport = game1.graphics.GraphicsDevice.Viewport;
                    aberturaTempo = (float)gameTime.ElapsedGameTime.TotalSeconds;
                    aberturaScale += aberturaTempo / 2;
                    aberturaOrigin = new Vector2(aberturaTextura.Width / 2, aberturaTextura.Height / 2);
                    aberturaPosicao = new Vector2(viewport.Width / 2, viewport.Height / 2);
                    textoFonte = game1.Content.Load<SpriteFont>("Fontes\\Verdana");
                    textoPosicao = new Vector2(viewport.Width/2, viewport.Height/2);
                    textoTexto = "Una produzione Bruno Matos e Julianna Baena.";
                    textoScale += aberturaTempo / 2 ;
                    textoOrigin = textoFonte.MeasureString(textoTexto)/2;
                    tempo3s -= gameTime.ElapsedGameTime;
                        spriteBatch.Draw(aberturaTextura, aberturaPosicao, null, Color.White, 0f, aberturaOrigin, aberturaScale, SpriteEffects.None, 1f);
                        spriteBatch.DrawString(textoFonte, textoTexto, textoPosicao, Color.Red, 0f, textoOrigin, textoScale, SpriteEffects.None, 1f);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor *alphaOut );
                    if (tempo3s.TotalSeconds <= 0)
                    {
                        alphaOut += 0.01f;
                        if (alphaOut >= 1.0f)
                        {
                            tempo3s = TimeSpan.Zero;
                            game1.telas = GameState.intro1;
                            alphaOut = .0f;
                        }
                    }
                    break;
                #endregion

                #region Intro1 - Olimpo externo
                case GameState.intro1:
                    
                    if (alphaIn <= 0.00f)
                    {
                        alphaIn = 0f;
                        alphaOut += .01f; //0.001f
                        spriteBatch.Draw(introOlimpo, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaOut);
                        if (alphaOut >= 1.0f) 
                        { 
                            game1.telas = GameState.intro2; 
                        }
                    }
                    else if (alphaIn <= 2.0f)
                    {
                        alphaIn -= .01f;
                        spriteBatch.Draw(introOlimpo, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaIn);
                    }
                    
                    break;

                #endregion

                #region Intro2 - Dentro do Olimpo
                case GameState.intro2:
                    if (alphaOut <= 0.00f)
                    {
                        alphaIn += .01f; //.001f
                        spriteBatch.Draw(introBanheira, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaIn);
                        if (alphaIn >= 1.0f) { game1.telas = GameState.intro3; }
                    }
                    else if (alphaOut <= 2.0f)
                    {
                        alphaOut -= .01f;
                        spriteBatch.Draw(introBanheira, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaOut);
                    }
                    if (controles.currentKeyboard.IsKeyDown(Keys.Escape) && controles.kbDelay > 300)
                    {
                        telas = GameState.Menu;
                        controles.kbDelay = 0;
                    }
                    
                    break;
                #endregion

                #region Intro3 - Zeus bebendo
                case GameState.intro3:
                   if (alphaIn <= 0.00f)
                    {
                        alphaIn = 0f;
                        alphaOut += .01f; //.001f
                        spriteBatch.Draw(introZeus, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaOut);
                        if (alphaOut >= 1.0f) { game1.telas = GameState.intro4; }
                    }
                    else if (alphaIn <= 2.0f)
                    {
                        alphaIn -= .01f;
                        spriteBatch.Draw(introZeus, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaIn);
                    }
                   if (controles.currentKeyboard.IsKeyDown(Keys.Escape) && controles.kbDelay > 300)
                   {
                       telas = GameState.Menu;
                       controles.kbDelay = 0;
                   }
                    break;
                #endregion

                #region Intro4 - Mojo Roubado
                case GameState.intro4:
                    if (alphaOut <= 0.00f)
                    {
                        alphaOut = 0f;
                        alphaIn += .01f; //.001f
                        spriteBatch.Draw(introMojo, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaIn);
                        if (alphaIn >= 1.0f) { game1.telas = GameState.intro5; }
                    }
                    else if (alphaOut <= 2.0f)
                    {
                        alphaOut -= .01f;
                        spriteBatch.Draw(introMojo, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaOut);
                    }
                    if (controles.currentKeyboard.IsKeyDown(Keys.Escape) && controles.kbDelay > 300)
                    {
                        telas = GameState.Menu;
                        controles.kbDelay = 0;
                    }
                    break;
                #endregion

                #region Intro5 - Fuga do templo
                case GameState.intro5:
                    if (alphaIn <= 0.00f)
                    {
                        alphaOut += .01f;
                        spriteBatch.Draw(introFuga, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaOut);
                        if (alphaOut >= 1.0f) { game1.telas = GameState.Menu; }
                    }
                    else if (alphaIn <= 2.0f)
                    {
                        alphaIn -= .01f;
                        spriteBatch.Draw(introFuga, Vector2.Zero, Color.White);
                        spriteBatch.Draw(fadeTextura, Vector2.Zero, cor * alphaIn);
                    }
                    if (controles.currentKeyboard.IsKeyDown(Keys.Escape) && controles.kbDelay > 300)
                    {
                        telas = GameState.Menu;
                        controles.kbDelay = 0;
                    }
                    break;
                #endregion

                #region Menu - menu principal
                case GameState.Menu:
                    spriteBatch.Draw(introMenu, Vector2.Zero, Color.White);
                    break;
                #endregion
            }
        }

    }
}